package org.example.config;

import org.example.bean.BeanE;
import org.example.bean.BeanF;
import org.example.bean.SingleBean;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Lazy;
import org.springframework.context.annotation.Scope;

import javax.annotation.PostConstruct;

@Configuration
public class SpringConfig {

    @Bean("beanF01")
    public BeanF beanF01() {
        BeanF beanF = new BeanF();
        beanF.setTag("注解开发");
        return beanF;
    }

    @Bean("beanF02")
    @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
    public BeanF beanF02() {
        BeanF beanF = new BeanF();
        beanF.setTag("注解开发");
        return beanF;
    }

    @Lazy
    @Bean("beanF03")
    public BeanF beanF03() {
        BeanF beanF = new BeanF();
        beanF.setTag("注解开发");
        return beanF;
    }

    @Lazy
    @Bean(name = "beanF04", initMethod = "init", destroyMethod = "destroy")
    public BeanF beanF04() {
        BeanF beanF = new BeanF();
        beanF.setTag("注解开发");
        return beanF;
    }

    @Bean(name = "beanF05")
    public BeanF beanF05(SingleBean singleBean, @Value("测试") String value) {
        System.out.println(singleBean.getTag());
        System.out.println(value);
        BeanF beanF = new BeanF();
        beanF.setTag("注解开发");
        return beanF;
    }
}
